﻿using System;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

namespace TestExtensions
{
    public abstract class Page<TPage>
        where TPage : class
    {
        public static TPage Parse(HtmlDocument document)
        {
            return (TPage)Activator.CreateInstance(typeof(TPage), document);
        }

        public static bool CanParse(HtmlDocument document, out TPage page)
        {
            var parsed = false;
            try
            {
                page = Parse(document);
                parsed = true;
            }
            catch
            {
                page = null;
            }
            return parsed;
        }
    }
}